package cn.lhl.core.demo.emoji.filter.cfg.emoji;

import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 处理提交数据中的表情符号 配置类
 *
 * @author liuhongliang
 * @version 2021/9/1
 */
@Slf4j
@EnableConfigurationProperties(EmojiProp.class)
@Configuration
public class EmojiCfg {

  /**
   * cmt
   */
  public EmojiCfg(EmojiProp emojiProp) {
    this.emojiProp = emojiProp;
  }

  private final EmojiProp emojiProp;

  /**
   * cmt
   */
  @Bean
  public FilterRegistrationBean emojiFilterRegistrationBean() {
    FilterRegistrationBean bean = new FilterRegistrationBean();
    bean.setFilter(new EmojiFilter(emojiProp));
    bean.setOrder(emojiProp.getOrder());
    bean.setEnabled(emojiProp.isEnabled());
    List<String> filteredUriList = emojiProp.getFilteredUriList();
    bean.addUrlPatterns(filteredUriList.toArray(new String[filteredUriList.size()]));
    return bean;
  }
}
